package com.indusfo.spc.service.impl;

import com.indusfo.spc.mapper.OrderChangeMapper;
import com.indusfo.spc.pojo.OrderChange;
import com.indusfo.spc.service.OrderChangeService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
public class OrderChangeServiceImpl implements OrderChangeService {
    @Resource
    private OrderChangeMapper orderChangeMapper;
    @Override
    public JSONObject queryOrderChangeList(OrderChange orderChange) {
        List<OrderChange> orderChangeList=new ArrayList<>();
        Integer pagesize = orderChange.getPagesize();
        Integer pageindex = orderChange.getPageindex();
        if(pagesize != null && pageindex != null) {
            orderChange.setIncept(pagesize*(pageindex - 1));
        }
        orderChangeList = orderChangeMapper.queryAllOrderChange(orderChange);
        if(!orderChangeList.isEmpty()){
            int countNums = orderChangeMapper.countAllOrderChange(orderChange);
            return JSONObject.oK("查询成功",orderChangeList,countNums);
        }
        return JSONObject.oK("查询成功",orderChangeList,0);
    }

    @Override
    public JSONObject queryOrderChangeNumber(Integer orderId) {
        if(!Optional.ofNullable(orderId).isPresent()){
            return JSONObject.build(JSONObject.ERROR,"未获取到任务单id");
        }
        Integer orderChangeNumber = orderChangeMapper.queryOrderChangeNumber(orderId);
        return JSONObject.build(JSONObject.SUCCESS,"查询成功",orderChangeNumber);
    }
}
